﻿/*=================================================================
* 版权信息：Copyright (C) 2005-2011 捷点科技 All Rights Reserved.
* 文件名称：CNVP_ProTypeRefExtendProperty.cs
* 创建标识：曾乃强 15158756652 2011-04-01 05:04:27
* 修改标识：
* 功能描述：
===================================================================*/
using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using CNVP.Framework.Helper;
using CNVP.Config;

namespace CNVP.JShop.DAL
{
    /// <summary>
    /// 对*CNVP_ProTypeRefExtendProperty*操作数据库(针对SQL Server)的实现
    /// </summary>
    public class CNVP_ProTypeRefExtendProperty
    {
       private string Prefix = DBConfig.Prefix;
        #region DAL
        public int Insert(Model.CNVP_ProTypeRefExtendProperty obj)
        {
            StringBuilder sql = new StringBuilder();
            sql.Append("insert into  " + Prefix + "ProTypeRefExtendProperty ([ProductTypeID],[ExtendPropertyName],[StageShowType],[IsShow],[SelectItemValue],[IsOrder])");
            sql.Append("values(@ProductTypeID,@ExtendPropertyName,@StageShowType,@IsShow,@SelectItemValue,@IsOrder)");
            sql.Append(";SELECT @@IDENTITY");
            SqlParameter[] pra = {
                            new SqlParameter("@ProductTypeID",obj.ProductTypeID),
							new SqlParameter("@ExtendPropertyName",obj.ExtendPropertyName),
							new SqlParameter("@StageShowType",obj.StageShowType),
							new SqlParameter("@IsShow",obj.IsShow),
							new SqlParameter("@SelectItemValue",obj.SelectItemValue),
							new SqlParameter("@IsOrder",obj.IsOrder)
                                 };
            return Convert.ToInt32(DbHelper.ExecuteScalar(sql.ToString(), pra));
        }

        public int Update(Model.CNVP_ProTypeRefExtendProperty obj)
        {
             StringBuilder sql = new StringBuilder();
             sql.Append("update " + Prefix + "ProTypeRefExtendProperty set [ProductTypeID] = @ProductTypeID,[ExtendPropertyName] = @ExtendPropertyName,[StageShowType] = @StageShowType,[IsShow] = @IsShow,[SelectItemValue] = @SelectItemValue,[IsOrder] = @IsOrder where [ID] = @ID");

            SqlParameter[] pra = { 
                            new SqlParameter("@ID",obj.ID),
							new SqlParameter("@ProductTypeID",obj.ProductTypeID),
							new SqlParameter("@ExtendPropertyName",obj.ExtendPropertyName),
							new SqlParameter("@StageShowType",obj.StageShowType),
							new SqlParameter("@IsShow",obj.IsShow),
							new SqlParameter("@SelectItemValue",obj.SelectItemValue),
							new SqlParameter("@IsOrder",obj.IsOrder)
                                };
             return DbHelper.ExecuteNonQuery(sql.ToString(),pra);
        }

        public int Delete(Model.CNVP_ProTypeRefExtendProperty obj)
        {
           StringBuilder sql = new StringBuilder();
           sql.Append("delete from " + Prefix + "ProTypeRefExtendProperty where [ID] = @ID");
           SqlParameter[] pra = {
                                new SqlParameter("@ID",obj.ID)
						
                                };
           return DbHelper.ExecuteNonQuery(sql.ToString(),pra);
        }

        public Model.CNVP_ProTypeRefExtendProperty LoadById(int ID)
        {
            
            StringBuilder sql = new StringBuilder();
            sql.Append("select [ProductTypeID],[ExtendPropertyName],[StageShowType],[IsShow],[SelectItemValue],[IsOrder] from " + Prefix + "ProTypeRefExtendProperty");
            sql.Append(" where [ID] = @ID");
            SqlParameter[] pra = {
                                 new SqlParameter("@ID",ID)
                                    };
            DataTable DT = DbHelper.ExecuteTable(sql.ToString(),pra);
            Model.CNVP_ProTypeRefExtendProperty cnvp_protyperefextendproperty = new Model.CNVP_ProTypeRefExtendProperty();
            if (DT != null && DT.Rows.Count > 0)
            {
                DataRow dr = DT.Rows[0];
                cnvp_protyperefextendproperty.ProductTypeID = dr["ProductTypeID"] is DBNull ? 0 : (int)dr["ProductTypeID"];
                cnvp_protyperefextendproperty.ExtendPropertyName = dr["ExtendPropertyName"] is DBNull ? String.Empty : (string)dr["ExtendPropertyName"];
                cnvp_protyperefextendproperty.StageShowType = dr["StageShowType"] is DBNull ? (byte)0 : (byte)dr["StageShowType"];
                cnvp_protyperefextendproperty.IsShow = dr["IsShow"] is DBNull ? (byte)0 : (byte)dr["IsShow"];
                cnvp_protyperefextendproperty.SelectItemValue = dr["SelectItemValue"] is DBNull ? String.Empty : (string)dr["SelectItemValue"];
                cnvp_protyperefextendproperty.IsOrder = dr["IsOrder"] is DBNull ? 0 : (int)dr["IsOrder"];
            }
             return cnvp_protyperefextendproperty;
        }

        #endregion

        /// <summary>
        /// 查看，产品类型ID
        /// </summary>
        /// <param name="ProductTypeID">产品类型ID</param>
        /// <returns></returns>
        public List<Model.CNVP_ProTypeRefExtendProperty> LoadAll(int ProductTypeID)
        {
            StringBuilder sql = new StringBuilder();
            sql.Append("select [ID],[ExtendPropertyName],[StageShowType],[IsShow],[SelectItemValue],[IsOrder] from " + Prefix + "ProTypeRefExtendProperty");
            sql.Append(" where [ProductTypeID] = @ProductTypeID Order by [IsOrder]");
            SqlParameter[] pra = {
                                 new SqlParameter("@ProductTypeID",ProductTypeID)
						
                                    };
            DataTable DT = DbHelper.ExecuteTable(sql.ToString(),pra);
            List<Model.CNVP_ProTypeRefExtendProperty> list = new List<Model.CNVP_ProTypeRefExtendProperty>();
            if (DT != null && DT.Rows.Count > 0)
            {
                foreach (DataRow dr in DT.Rows)
                {
                    Model.CNVP_ProTypeRefExtendProperty cnvp_protyperefextendproperty = new Model.CNVP_ProTypeRefExtendProperty();
                    cnvp_protyperefextendproperty.ID = dr["ID"] is DBNull ? 0 : (int)dr["ID"];
                    cnvp_protyperefextendproperty.ExtendPropertyName = dr["ExtendPropertyName"] is DBNull ? String.Empty : (string)dr["ExtendPropertyName"];
                    cnvp_protyperefextendproperty.StageShowType = dr["StageShowType"] is DBNull ? (byte)0 : (byte)dr["StageShowType"];
                    cnvp_protyperefextendproperty.IsShow = dr["IsShow"] is DBNull ? (byte)0 : (byte)dr["IsShow"];
                    cnvp_protyperefextendproperty.SelectItemValue = dr["SelectItemValue"] is DBNull ? String.Empty : (string)dr["SelectItemValue"];
                    cnvp_protyperefextendproperty.IsOrder = dr["IsOrder"] is DBNull ? 0 : (int)dr["IsOrder"];
                    list.Add(cnvp_protyperefextendproperty);
                }
            }
            return list;

        }

        public int DeleteNotIn(int ProductTypeID, string nowid)
        {
            StringBuilder sql = new StringBuilder();
            sql.Append("delete from " + Prefix + "ProTypeRefExtendProperty where [ProductTypeID]=" + ProductTypeID + " and [ID] not in (" + nowid + ")");
            return DbHelper.ExecuteNonQuery(sql.ToString());
        }
    }
}

